import express from "express";
import { taskList } from "../const/index.js";
import Result from "../common/result.js";

const messageRouter = express.Router();

messageRouter.post("/find", async (req, res) => {
  const { taskId } = req.body;
  const task = taskList.get(taskId);
  if (!task) {
    return res.send(Result.success(false, "任务不存在"));
  }
  if (!task.done) {
    return res.send(Result.success(false, "任务未完成"));
  }
  taskList.delete(taskId);
  return res.send(Result.success(true, "任务已经完成"));
});

export default messageRouter;
